<?php
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$return=array();
$tabs=array(
	array('op'=>'list','title'=>'分佣记录'),
);
set_html('tabs',$tabs);
if($_RQ['op']=='list'){
	$params=array('uniacid'=>$_SESSION['uniacid']);
	if($_RQ['mid']){
		$params['mid']=intval($_RQ['mid']);
		$return['params']['mid']=$_RQ['mid'];
	}
	if(isset($_RQ['status'])){
		$params['status']=intval($_RQ['status']);
		$return['params']['status']=$_RQ['status'];
	}
	$psize=20;
	$pindex=intval($_RQ['page'])?:1;
	$parameter=array(
		'params'=>$params,
		'limit'=>array($pindex,$psize),
		'orderby'=>'id desc',
	);
	$list=$this->get_list('upfee',$parameter,$total);
	if($list){
		foreach($list as &$item){
			$item['member']=cfc('core')->member_show($item['mid']);
			$item['nmember']=cfc('core')->member_show($item['n_mid']);
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'list'=>array(
			'tip'=>'按每月，自动结算费用，针对最大等级（且存在平级的）老板(上级)的分佣奖励。',
			'data'=>'list','edit'=>false,'del_one'=>false,'delall'=>false,'list'=>array(
			array('name'=>'member','title'=>'店主','type'=>'member'),
			array('name'=>'allfee','title'=>'分佣总额','type'=>'string'),
			array('name'=>'fee','title'=>'获得分佣','type'=>'string'),
			array('name'=>'month','title'=>'月份','type'=>'string'),
			array('name'=>'createtime','title'=>'生成时间','type'=>'time'),
		),'batch'=>array(
			array('type'=>'post','url'=>'/max_redlog/updata/','title'=>'一键发放上月分佣'),
		)),
		'search'=>array(
			array('type'=>'choose','width'=>15,'action'=>'core/member.get_member/','name'=>'mid','title'=>'选择会员'),
			array('type'=>'radio','width'=>15,'name'=>'status','title'=>'状态','options'=>'upfee_status'),
		),
	);
	$return['htmls']=$htmls;
	$return['upfee_status']=$this->upfee_status;
	exi($return);
}
if($_RQ['op']=='updata'){
	$this->model('model')->add_upfee();
	exi('一键发放成功！');
}
if($_RQ['op']=='detail'){
	$item=$this->get('upfee',array('id'=>intval($_RQ['id'])),array('id','remark'));
	if(!$item){
		exi('指定佣金不存在！','error');
	}
	$item['member']=cfc('core')->member_show($item['mid']);
	$item['nmember']=cfc('core')->member_show($item['n_mid']);
	$item['timeno']=date('Ymd',$item['end_time']);
	$return['item']=$item;
	$return['htmls']=array(
		'type'=>'look',
		'desc'=>'佣金明细',
		'look'=>array(
			array('name'=>'member','title'=>'店主','type'=>'member'),
			//array('name'=>'nmember','title'=>'下级','type'=>'member'),
			array('name'=>'allfee','title'=>'分佣总额','type'=>'string'),
			array('name'=>'fee','title'=>'获得分佣','type'=>'string'),
			array('name'=>'month','title'=>'月份','type'=>'string'),
			array('name'=>'month','title'=>'月份','type'=>'string'),
			//array('name'=>'status','title'=>'状态','type'=>'status'),
			array('name'=>'createtime','title'=>'生成时间','type'=>'time'),
		),
	);
	$return['htmls']=$htmls;
	exi($return);
}